home *** CD-ROM | disk | FTP | other *** search
/ Aminet 6 / Aminet 6 - June 1995.iso / Aminet / util / shell / dbGoodies.lha / goodies / ShowPorts.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-15  |  1.1 KB  |  54 lines

  1. /*
  2. **  ShowPorts.c by Daniel Balster
  3. **
  4. **  lists all message ports by name to stdout
  5. **
  6. **  useful to get a quick overview of all ports or if you are searching for
  7. **  the name of an arexxport of an unknown application.
  8. **
  9. **  needs os20 or higher, terminates quitely if the requested OS is not available.
  10. **  must be run from cli/shell or the wb's "execute command" ability.
  11. */
  12.  
  13. #include <exec/exec.h>
  14. #include <dos/dos.h>
  15. #include <clib/exec_protos.h>
  16. #include <clib/dos_protos.h>
  17.  
  18. extern struct ExecBase *SysBase;
  19.  
  20. /*  no use of init/startup/exit code to gain bytes */
  21.  
  22. void _main( void )
  23. {
  24.     struct Library  *DOSBase;
  25.  
  26.     if( DOSBase = OpenLibrary( "dos.library", 37L ) )
  27.     {
  28.     struct Process *process = FindTask( 0 );
  29.     if( process->pr_CLI )
  30.     {
  31.         Forbid();
  32.  
  33.         struct Node *node = (struct Node *) SysBase->PortList.lh_Head;
  34.  
  35.         do {
  36.         VPrintf( "%s\n", &(node->ln_Name) );
  37.         node = node->ln_Succ;
  38.         } while( node );
  39.  
  40.         Permit();
  41.     }
  42.     else
  43.     {
  44.         /*    workbench stuff.
  45.         do not add an icon, it should only be used by shell */
  46.  
  47.         WaitPort( &process->pr_MsgPort );
  48.         ReplyMsg( GetMsg( &process->pr_MsgPort ) );
  49.     }
  50.  
  51.     CloseLibrary( DOSBase );
  52.     }
  53. }
  54.